package com.study.hospital_3.service;

import com.study.hospital_3.mapper.InstrumentMapper;
import com.study.hospital_3.pojo.Instrument;
import com.study.hospital_3.vo.InstrumentUpdateVO;
import com.study.hospital_3.vo.InstrumentVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class InstrumentService {
    @Resource
    private InstrumentMapper instrumentMapper;


    public Map<String, Object> selectInstrument(InstrumentVo instrumentVo){
        System.out.println(instrumentVo.getPage());
        System.out.println(instrumentVo.getLimit());
        System.out.println(instrumentVo.getInstrumentname());
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "查询仪器列表成功");
        map.put("data", instrumentMapper.selectInstrument(instrumentVo));
        return map;
    }

    public Map<String, Object> insert(InstrumentVo instrumentVo) {
        Instrument instrument = new Instrument();
        BeanUtils.copyProperties(instrumentVo,instrument);
        instrumentMapper.insert(instrument);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "新增仪器成功");
        map.put("data", instrument);
        return map;
    }

    public Map<String, Object> deleteById( Integer id) {
        Map<String, Object> map = new HashMap<>();
        instrumentMapper.deleteById(id);
        map.put("code", 200);
        map.put("msg", "删除仪器成功");
        return map;
    }


    public Map<String, Object> updateById(InstrumentUpdateVO instrumentUpdateVO) {
        Map<String, Object> map = new HashMap<>();
        instrumentMapper.updateById(instrumentUpdateVO);
        map.put("code", 200);
        map.put("msg", "更新仪器成功");
        return map;
    }





}
